/*
 * @Author: 薛严 348352046@qq.com
 * @Date: 2023-04-13 16:33:50
 * @LastEditors: 薛严 348352046@qq.com
 * @LastEditTime: 2023-04-13 16:52:24
 * @FilePath: /vite/ift-file-md5-uni-react/src/SingUpload.jsx
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { useState } from "react"
import {getFileSignature} from 'ift-util';
import {getOption} from './util'
const Index  = () => {
  const [imageSrc, setImageSrc] = useState('https://img.yzcdn.cn/vant/cat.jpeg')
  const change = async (e)=>{
    const file = e.target.files[0];
    // const fileType = file.name.split(".")[1];
    const fileType = file.name.slice(file.name.lastIndexOf('.') + 1);
    const r = await getFileSignature(file, fileType);
    console.log(r);
    const form = new FormData();
    form.append("file", file)
    let options = getOption(r, form)
    const url =
      "https://dev-ftecard.aijiatui.com/gov-file-upload/security/single-upload";
    const res = await fetch(url, options);
    const data = await res.json();
    console.log(data.data.fileUrls[0]);
    setImageSrc(data.data.fileUrls[0])
  }
  return (
    <>
    <p>{imageSrc}</p>
    <img src={imageSrc}  />
      <div>单个文件上传</div>
      <input  type="file"  onChange={change}  />
    </>
  )
}

export  default Index